
package org.example.library;

import java.util.regex.Pattern;

public class ValidarCampos {
    
    String Expresion_mail = "^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$";
    String Expresion_password = "^\\w{6,10}";
    String Expresion_nombre = "^\\p{alpha}{2,15}";
    String Expresion_apellido = "^(\\w+(\\p{space}\\w+)?){1,20}";
    String Expresion_telefono = "^\\d{9}";
    String Expresion_ncomen = "^[1-9]+";
        
    public int checkregistrodata(String mail ,String password, String password2, String name, String sname, String tlf ){
            try {
                if(!Pattern.compile(Expresion_mail).matcher(mail).matches())return 1;
                if(!Pattern.compile(Expresion_password).matcher(password).matches() || password2==null || password==null || !password.equals(password2))return 2;
                if(!Pattern.compile(Expresion_nombre).matcher(name).matches())return 3;
                if(!Pattern.compile(Expresion_apellido).matcher(sname).matches())return 4;
                if(!Pattern.compile(Expresion_telefono).matcher(tlf).matches())return 5;
                return 0;
            }
            catch (Exception e){return 6;}
    }
    
    public int checklogindata(String mail ,String password ){
        try{
            if(!Pattern.compile(Expresion_mail).matcher(mail).matches())return 1;
            if(!Pattern.compile(Expresion_password).matcher(password).matches())return 2;
            else return 0;
        }
        catch (Exception e){return 3;}
    } 
    
}
